package info.itloser.learnkotlindemo.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import info.itloser.learnkotlindemo.R
import info.itloser.learnkotlindemo.bean.BaseItem

/**
 * Created by itloser.info
 * on 2021/6/21
 */
class FragmentSimpleAdapter : RecyclerView.Adapter<FragmentSimpleAdapter.SimpleHolder>() {

    private var baseItems: List<BaseItem> = ArrayList()

    class SimpleHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var tvTile: TextView? = null
        var tvContent: TextView? = null

        init {
            tvTile = itemView.findViewById(R.id.tv_title)
            tvContent = itemView.findViewById(R.id.tv_content)
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleHolder {

        return SimpleHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_simple, parent, false)
        )
    }

    override fun onBindViewHolder(holder: SimpleHolder, position: Int) {
        val item = baseItems[position]
        holder.tvTile?.text = item.title
        holder.tvContent?.text = item.desc

    }

    override fun getItemCount(): Int {
        return baseItems.size
    }

}